package com.ibm.cloud.banking.account.service;

import com.ibm.cloud.banking.annotation.PBS;
import com.ibm.cloud.banking.facade.account.IAccountFacade;
import com.ibm.cloud.banking.facade.account.dto.AccountBalanceUpdateDTO;
import com.ibm.cloud.banking.platform.context.service.RequestContextHandler;
import com.ibm.cloud.invoker.PbsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

@PBS(servNo = "PBS100002")
@Slf4j
public class TransferInService implements PbsService<AccountBalanceUpdateDTO, String> {

    @Autowired
    IAccountFacade accountFacade;

    private final static String COMPENSATE_PARAMS_KEY = "acct-transfer-in-param-key";

    @Override
    public String doService(AccountBalanceUpdateDTO accountBalanceUpdateDTO) {
        RequestContextHandler.putCompensate(COMPENSATE_PARAMS_KEY,accountBalanceUpdateDTO);
        return accountFacade.acctTransferIn(accountBalanceUpdateDTO);
    }

    @Override
    public void compensate(AccountBalanceUpdateDTO data) {
        data = (AccountBalanceUpdateDTO)RequestContextHandler.getCompensate(COMPENSATE_PARAMS_KEY);
        accountFacade.acctTransferInRefund(data);

    }
}
